<?php

namespace app\api\model\wine;

use app\common\model\BaseModel;
use app\common\model\Order;

class DermemberProfitBill extends BaseModel
{
    protected $autoWriteTimestamp = true;

    protected $name = 'dermember_profit_bill';

    // 我的分润流水
    public static function shareFlow(int $user_id)
    {
        // float_amount 浮动金额
        return self::where(['user_id'=>$user_id,'store_id'=>getStoreId()])
            ->order('create_time','desc')
            ->paginate(15);
    }

    // 我的分润流水
    public static function shareFlowAll(int $user_id)
    {
        return self::where(['user_id'=>$user_id,'store_id'=>getStoreId()])
            ->sum('float_amount');
    }

    // 按时间段查询分润额
    public static function shareTime(int $user_id,string $startTime,string $endTime){
        return self::where(['user_id'=>$user_id,'store_id'=>getStoreId()])
            ->whereBetweenTime('create_time',$startTime,$endTime)
            ->sum('float_amount');
    }

    // 我的现金流水
    public static function cashFlow(int $user_id){
        return Order::where(['store_id'=>getStoreId(),'is_delete'=>0,'pay_status'=>20,'user_id'=>$user_id])
            ->order('create_time','desc')
            ->paginate(15);
    }

    // 我的现金流总额
    public static function cashFlowAll(int $user_id){
        return Order::where(['store_id'=>getStoreId(),'is_delete'=>0,'pay_status'=>20,'user_id'=>$user_id])
            ->sum('pay_price');
    }

    // 按时间段查询现金流总额
    public static function cashFlowTime(int $user_id,string $startTime,string $endTime){
        return Order::where(['store_id'=>getStoreId(),'is_delete'=>0,'pay_status'=>20,'user_id'=>$user_id])
            ->whereBetweenTime('create_time',$startTime,$endTime)
            ->sum('pay_price');
    }
}
